package com.yingside.collection;

import java.util.*;

public class TestUtils {
    public static void main(String[] args) {

        Integer [] nums = {34,77,11,9,345,8};

        System.out.println(Arrays.toString(nums));

        System.out.println("=========升序排序========");
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));

        System.out.println("=========自定义排序========");
        Arrays.sort(nums,new MyComparator());
        System.out.println(Arrays.toString(nums));


        Teacher [] teachers = new Teacher[4];
        teachers[0] = new Teacher(3,"张老师");
        teachers[1] = new Teacher(1,"里老师");
        teachers[2] = new Teacher(2,"往老师");
        teachers[3] = new Teacher(4,"五老师");

        System.out.println("=========默认打印========");
        for (Teacher teacher:teachers) {
            System.out.println("teacher = " + teacher);
        }

        Arrays.sort(teachers,new TeacherComparator());
        System.out.println("=========老师对象通过id排序之后打印========");
        for (Teacher teacher:teachers) {
            System.out.println("teacher = " + teacher);
        }

        System.out.println("===============Collections====================");

        List<Integer> list = new ArrayList<>();
        list.add(56);
        list.add(11);
        list.add(45);
        list.add(89);

        Collections.sort(list);

        System.out.println("list = " + list);

        List<Teacher> teacherList = new ArrayList<>();
        Teacher teacher1 = new Teacher(3, "张老师");
        Teacher teacher2 = new Teacher(1, "w老师");
        Teacher teacher3 = new Teacher(4, "L老师");
        Teacher teacher4 = new Teacher(2, "f老师");
        teacherList.add(teacher1);
        teacherList.add(teacher2);
        teacherList.add(teacher3);
        teacherList.add(teacher4);

        Collections.sort(teacherList,new TeacherComparator());

        System.out.println("teacher4 = " + teacherList);

        //随机乱序
        /*Collections.shuffle(teacherList);
        System.out.println("==============随机乱序=================");
        System.out.println("teacher4 = " + teacherList);*/

        //倒序
        /*Collections.reverse(teacherList);
        System.out.println("==============倒序=================");
        System.out.println("teacher4 = " + teacherList);*/

        //把线程不安全的ArrayList转换成线程安全的集合
        //Collections.synchronizedList(teacherList);
        /*List<Teacher> ts = new ArrayList<>();
        ts.add(new Teacher());
        ts.add(new Teacher());
        ts.add(new Teacher());
        ts.add(new Teacher());

        Collections.copy(ts,teacherList);

        System.out.println("ts = " + ts);*/


//        Teacher max = Collections.max(teacherList, new TeacherComparator());
//        System.out.println("max = " + max);

        //直接生成一个空的集合对象
        List<Object> objects = Collections.emptyList();

        //通过Collections.sort对图书排序（价格）
        //Collections.shuffle();这个方法有什么作用
        //Collections.reverse();这个方法有什么作用

    }
}
